<template>
  <view>
    <view class="noAuth">
      <image src="/static/xslogo.png" mode="widthFix"></image>
      <view class="title">劳动教育管理平台教师端</view>
        <!--  @getuserinfo="getUserInfo"  @getphonenumber="getPhoneNumber" -->
        
        <button @click="handelLogin" v-if="isAuth">一键登录</button>
        <view v-else>
          <button v-if="!isAgree" @click="handelyz">手机号绑定并登录</button>
          <button v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号绑定并登录</button>
        </view>
        <view class="xy-warp" v-if="!isAuth">
        <view class="xy">
          <radio value="r1" :checked="isAgree"   @click="isAgree = !isAgree"/>
            <view class="fs-24 col888">已阅读并同意 
              <text style="color: #4878FF;" @click="toPage('1')">《用户协议》</text> 
              <text style="color: #4878FF;" @click="toPage('2')">《隐私协议》</text> 
            </view>
        </view>
		<view class="fs-24 col888" style="margin-top: 10px; white-space: pre-wrap;text-align: left;text-indent: 2em;">
      &nbsp;&nbsp;请用临沂大学统一身份认证平台中的手机号接收验证码，进行绑定操作。如果此号码不再使用，请到统一身份认证平台更换手机号，更换手机号一个小时后再试。
		</view>
      </view>
    </view>

    <!-- 底部 -->
    <view class="footer">技术支持由山东风正信息科技有限公司提供</view>
  </view>
</template>

<script>
  export default {
   
   
     data() {
      return {
        isAgree:false,
        phone:'',
        code:'',
        // 是否授权
         isAuth:false,
        openId:''
      };
       
    },
    
    onLoad() {
      uni.login({
        provider: "weixin",
        success: (res) => {
          console.log("登录", res);
          if (res.errMsg == "login:ok") {
            this.$tools.axiosFromToken('POST',`login/getOpenIdTer?code=${res.code}`,{},'').then(res =>{
            this.openId = res.data.openId
            this.isAuth = res.data.flag
          })
          }
        },
      })
    
    },
    methods:{
      handelyz(){
        if(!this.isAgree) return this.$tools.showtt('请阅读并同意协议')
      },
      getPhoneNumber(e){
       this.$tools.axiosFromToken('POST','login/getPhoneNumberTer',{code:e.detail.code},'').then(res =>{
          this.phone = res.phone_info.phoneNumber
          if(this.phone){
            this.login()
          }
        })
      },
      handelLogin() {
        this.login()
      },
      toPage(type){
        uni.navigateTo({
          url:'/pages/login/agreement?type='+type
        })
      },
      login(){
        this.$tools.axiosFromToken('POST','login/loginTer',{phone:this.phone,openId:this.openId},'加载中').then(res => {
          if(res.code != 200) return this.$tools.showtt(res.msg)
          let {data:{token}} = res
          uni.setStorageSync('token',token)
          uni.switchTab({
            url:'/pages/index/index'
          })
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
.noAuth{
  text-align: center;
  height: 100%;
  image{
    margin-top: 200rpx;
    width: 300rpx;
    height: 310rpx;
    // border: 2rpx solid pink;
    border-radius: 50%;
   
  }
  .title{
    font-size: 48rpx;
    margin: 20px 0;
  }
  input{
    text-align: left;
    width: 80%;
    height: 80rpx;
    margin: 30px auto;
    border: 1rpx solid #ccc;
    border-radius: 10rpx;
    padding-left: 20rpx;

  }
  .phone-warp{
    position: relative;
    .code{
      position: absolute;
      right: 12%;
      top: 20rpx;
      color: blue;
      cursor: pointer;
    }
  }
  button{
    width: 90%;
    height: 80rpx;
    background-color: blue;
    color: #fff;
    border-radius: 10rpx;
    margin-top: 180px;
    border-radius: 10px;
    line-height: 80rpx;
  }
  .xy-warp{
    // padding-left: 10%;
    width: 80%;
    margin: 20px auto;
   
    .xy{
      width: 100%;
      height: 80rpx;
      text-align: center;
      border-top: 2rpx solid #ccc;
      border-bottom: 2rpx solid #ccc;
      display: flex;
      align-items: center;
      justify-content: space-around;
    }
  }
  
}

.footer{
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
}

</style>
